//
//  ZTTXAutoTrackUtils.m
//  APPDemo
//
//  Created by 郭红旗 on 2021/10/18.
//

#import "ZTTXAutoTrackUtils.h"
#import "ZTTXConstants.h"
#import "ZTTXVisualizedManager.h"
#import "UIView+AutoTrack.h"
#import "NSObject+Utils.h"

@implementation ZTTXAutoTrackUtils

+ (NSMutableDictionary<NSString *, NSString *> *)propertiesWithAutoTrackObject:(id)object viewController:(nullable UIViewController <ZTTXAutoTrackViewControllerProperty>*)viewController {
    return [self propertiesWithAutoTrackObject:object viewController:viewController isCodeTrack:NO];
}

+ (NSMutableDictionary<NSString *, NSString *> *)propertiesWithAutoTrackObject:(id<ZTTXAutoTrackViewProperty>)object viewController:(nullable UIViewController <ZTTXAutoTrackViewControllerProperty>*)viewController isCodeTrack:(BOOL)isCodeTrack {
   

    NSMutableDictionary *properties = [[NSMutableDictionary alloc] init];
    
    viewController = viewController ? : object.sensorsdata_viewController;
    NSDictionary *dic = [self propertiesWithViewController:viewController];
    [properties addEntriesFromDictionary:dic];
    // ViewID
    UIView *view = (UIView *)object;
    NSDictionary *viewPathProperties = [[ZTTXVisualizedManager sharedInstance] propertiesWithView:view];
    if (viewPathProperties) {
        [properties addEntriesFromDictionary:viewPathProperties];
    }
    
    [properties addEntriesFromDictionary:self.deviceInfo];
  
    return properties;
}

+ (NSDictionary<NSString *, NSString *> *)propertiesWithViewController:(UIViewController <ZTTXAutoTrackViewControllerProperty> *)viewController {
    NSMutableDictionary *properties = [[NSMutableDictionary alloc] init];
    properties[kZTTXEventPropertyScreenName] = viewController.sensorsdata_screenName;
    properties[kZTTXEventPropertyTitle] = viewController.sensorsdata_title;
        
    return [properties copy];
}

@end
